<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use DB;
use Config;
use App\User;

class UsersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $users = new User();
        $data = $users->getUsersInfo();

        if ($data){
            $info = $this->display(Config::get('3cs.CODE_SUCCESS'),$data);
        }else{
            $info = $this->display(Config::get('3cs.CODE_ERROR'),$data);
        }

        return $info;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

        $users = new User();
        $data =  $users->getUserInfo($id);

//        dd($data);

        if ($data){
            $info = $this->display(Config::get('3cs.CODE_SUCCESS'),$data);
        }else{
            $info = $this->display(Config::get('3cs.CODE_ERROR'),$data);
        }

        return $info;


    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {



    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $users = new User();
        if($users->updateUserInfo($request->all(), $id)){
            echo 'ok';
        }else{
            echo 'no';
        }

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {

//        $posts = User::onlyTrashed()->get();
////        $posts = User::withTrashed()->get();
//        dd($posts->toArray());



        $post = User::find($id);
        $post->delete();
        if($post->trashed()){
            echo '软删除成功！';
            dd($post);
        }else{
            echo '软删除失败！';
        }


        //
//        dd($id);




//        $user = User::withTrashed()->get();
//
//        dd($user);


        $user = User::find($id);

//        $user->restore();
//        dd($user);

        return $user->trashed();
        dd($user);

        $user->delete();
        if($user->trashed()){
            echo '软删除成功！';
            dd($user);
        }else{
            echo '软删除失败！';
        }


    }
}
